package cmd.commands;

import java.util.logging.Level;

import util.LoggingUtils;
import cmd.CommandType;

/**
 * This
 * 
 * @author Yang
 * 
 */
public class Command {
	protected CommandType	command;
	protected String[]		parameters;

	public CommandType getCommand() {
		return this.command;
	}

	public String[] getParameters() {
		return this.parameters;
	}

	public Command(CommandType command, String[] params) {
		this.command = command;
		this.parameters = params;
	}

	public boolean execute() {
		return false;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		int numParams = this.parameters.length;
		sb.append(this.command.toString());
		for (int i = 0; i < numParams; i++) {
			sb.append(" ").append(this.parameters[i]);
		}
		return sb.toString();
	}

	protected int[] getIntegerParameterList() {
		int length = this.parameters.length;
		int[] intParameterArr = new int[length];

		for (int i = 0; i < length; i++) {
			try {
				intParameterArr[i] = Integer.parseInt(this.parameters[i]);
			} catch (NumberFormatException ex) {
				System.err.println("The parameter should be in integer format, '" + this.parameters[i]
						+ "' cannot be converted to an integer.");
				String classMethod = "cmd.commands.command in getIntegerParameterList()";
				LoggingUtils.log(Level.SEVERE, "in " + classMethod + ex.getMessage(),ex);
				return null;
			}
		}
		return intParameterArr;
	}
}